package com.wanmait.employment.webController;



import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.*;
import com.wanmait.employment.service.*;
import com.wanmait.employment.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("web/recruitmentPost")
public class WebRecruitmentPostController {


    @Resource
    private RecruitmentPostService recruitmentPostService;

    @Resource
    private ExpectedSalaryService expectedSalaryService;

    @Resource
    private IndustryService industryService;

    @Resource
    private WorkExperienceService workExperienceService;

    @Resource
    private RecruitmentEducationService recruitmentEducationService;

    @Resource
    private NatureWorkService natureWorkService;

    @Resource
    private AddressService addressService;

    @Resource
    private JobWelfareLabelBasicsService jobWelfareLabelBasicsService;

    @Resource
    private WelfareLabelBasicsService welfareLabelBasicsService;

    @GetMapping("list")
    public AjaxResult list(Integer publisherId,String title,String currentStatus,Integer pageNum,Integer pageSize,String currentDate){

        PageInfo<RecruitmentPost> recruitmentPostPageInfo=recruitmentPostService.findByPublisherId(publisherId,title,currentStatus,pageNum,pageSize,currentDate);
        System.out.println(recruitmentPostPageInfo.getList());
        return AjaxResult.success("获取列表成功").put("recruitmentPostPageInfo",recruitmentPostPageInfo);
    }

    @PostMapping("updateStatus")
    public AjaxResult updateStatus(String idArray,String jobStatus){
       recruitmentPostService.updateStatus(idArray,jobStatus);
        return AjaxResult.success("success");
    }
    @DeleteMapping("delete")
    public AjaxResult delete(String idArray){
        recruitmentPostService.deleteByIds(idArray);
        return AjaxResult.success("success");
    }
    @GetMapping("selectById")
    public AjaxResult selectById(Integer id){
        RecruitmentPost recruitmentPost=recruitmentPostService.findById(id);
        return AjaxResult.success("success").put("recruitmentPost",recruitmentPost);
    }
    @GetMapping("expectedSalaryList")
    public AjaxResult expectedSalaryList(){
        List<ExpectedSalary> expectedSalaryList=expectedSalaryService.selectList("");
        return AjaxResult.success("success").put("expectedSalaryList",expectedSalaryList);
    }
//    获取行业
    @GetMapping("industryList")
    public AjaxResult industryList(){
        List<Industry> industryList=industryService.selectAllById();
        System.out.println(industryList);
        return AjaxResult.success("success").put("industryList",industryList);
    }

//获取经验时长数组
    @GetMapping("workExperienceList")
    private AjaxResult workExperienceList(){
        List<WorkExperience> workExperienceList=workExperienceService.selectList("");
        return AjaxResult.success("success").put("workExperienceList",workExperienceList);
    }

//    获取学历数组
    @GetMapping("recruitmentEducationList")
    private AjaxResult recruitmentEducationList(){
        List<RecruitmentEducation> recruitmentEducationList=recruitmentEducationService.selectList("");
        return AjaxResult.success("success").put("recruitmentEducationList",recruitmentEducationList);
    }
//    获取工作类型列表
    @GetMapping("natureWorkList")
    private AjaxResult natureWorkList(){
        List<NatureWork> natureWorkList=natureWorkService.findAll("");
        return AjaxResult.success("success").put("natureWorkList",natureWorkList);
    }
//    获取省列表
    @GetMapping("provinceList")
    private AjaxResult provinceList(){
        List<Address> provinceList=addressService.provinceList();
        return AjaxResult.success("success").put("provinceList",provinceList);
    }

    //    获取市列表
    @GetMapping("cityList")
    private AjaxResult cityList(Integer provinceId){
        List<Address> cityList=addressService.cityList(provinceId);
        return AjaxResult.success("success").put("cityList",cityList);
    }
    //    获取区列表
    @GetMapping("areaList")
    private AjaxResult areaList(Integer cityId){
        List<Address> areaList=addressService.areaList(cityId);
        return AjaxResult.success("success").put("areaList",areaList);
    }
//    获取职位福利标签数组
    @GetMapping("welfareLabelBasicsList")
    private AjaxResult welfareLabelBasicsList(){
        List<WelfareLabelBasics> welfareLabelBasicsList=welfareLabelBasicsService.list();
        return AjaxResult.success("success").put("welfareLabelBasicsList",welfareLabelBasicsList);
    }

    //有关公司前台主页公司职位
    @GetMapping("searchRecruitmentPost")
    public AjaxResult searchPublisher(Integer companyId){
        List<RecruitmentPost> recruitmentPostList=recruitmentPostService.searchList(companyId);
        return AjaxResult.success("success").put("recruitmentPostList",recruitmentPostList);

    };
//    发布招聘职位
    @PostMapping("saveOrUpdate")
    private AjaxResult saveOrUpdate(@RequestBody RecruitmentPost recruitmentPost, String type,String checkList){

        recruitmentPostService.saveOrUpdatePost(recruitmentPost,type,checkList);
        return AjaxResult.success("success");
    }

}
